package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Autowired
    private ItemMapper itemMapper;

    @Override
    public PageDTO getlist(int page, int size) {
        Page<Item> page1=new Page(page,size);
        LambdaQueryWrapper<Item> queryWrapper = new LambdaQueryWrapper();
queryWrapper.orderByAsc(Item::getId);
        Page<Item> page2 = itemMapper.selectPage(page1, queryWrapper);
        List<Item> records = page2.getRecords();
        long total = page2.getTotal();
        PageDTO pageDTO = new PageDTO(total, records);

        return pageDTO;
    }


}
